package com.compmov.socialnetwork;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.Toast;

import com.compmov.datamodel.Comentario;
import com.compmov.libraries.CommentAdapter;
import com.compmov.webservice.ComentarioWSClient;
import com.compmov.webservice.WSClientException;

public class Comments extends Activity {


	private ListView list;
	CommentAdapter adapter;
	private String id;

	static final String[] COUNTRIES = new String[] {
		"Comentario 1", "Comentario 2", "Comentario 3", "Comentario 4", "Comentario 5",
	};


	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.coments);

		Bundle extras = getIntent().getExtras();
		id = extras.getString("id_lugar");


		list = (ListView)findViewById(R.id.lst_commentsList);	  
		ComentarioWSClient comentarioWS = new ComentarioWSClient("comentario");
		try{
			List<Comentario> comentarios = comentarioWS.getComentarios(Integer.parseInt(id));
			adapter=new CommentAdapter(this, comentarios);
			list.setAdapter(adapter);

		} catch (WSClientException e) {
			Toast.makeText(getBaseContext(),"Error en el servidor. Intente de nuevo",
					Toast.LENGTH_SHORT).show();
		}
	}

	@Override
	public void onDestroy() {
		adapter.imageLoader.stopThread();
		list.setAdapter(null);
		super.onDestroy();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu_comments, menu);
		return true;
	}

	//  @Override
	public boolean onOptionsItemSelected(MenuItem item) {
		Intent intent;
		switch (item.getItemId()) {
		case R.id.itemAdd:
			intent = new Intent(this.getApplicationContext(),AddComments.class);
			 intent.putExtra("id_lugar", id);
			startActivity(intent);   		                     
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}


}

